import time
import random

class Role():
    def __init__(self, name, sex, equipment, blood=100):
        self.name = name
        self.sex = sex
        self.blood = blood
        self.equipment = equipment

    def attack(self, role):
        print("普通攻击")
        role.blood -= 5

    def defense(self, role):
        if role.equipment == 1 and role.blood <= 100:
            role.blood += 5

class Thug(Role):

    def skill_one(self, role):
        print("浮空六连刺!")
        role.blood -= 10

    def skill_two(self, role):
        print("落花掌!!")
        role.blood -= 20

    def skill_three(self, role):
        print("龙抬头!!!")
        role.blood -= 30


class Warrior(Role):

    def skill_one(self, role):
        print("生命回复!")
        self.blood += 20
        if self.blood > 100:
            self.blood = 100

    def skill_two(self, role):
        print("回风枪!!")
        role.blood -= 20

    def skill_three(self, role):
        print("燎原百斩!!!")
        role.blood -= 25


class Room():
    count = 0
    def __init__(self, num):
        self.room_num = num

    def join_room(self, roomdict, role):
        roomdict[role.name] = self.room_num

roomdict = {}
roledict = {}
print("欢迎来到巅峰对决".center(40))
for i in range(2):
    option = input(f"输入要创建的角色{i+1}(1--战士 2--刺客)：")
    role_name = input("输入角色名：")
    if role_name in roledict.keys():
        print("该角色名已经存在")
        continue
    role_sex = input("输入角色性别：")
    role_equipment = input("是否有装备：")

    if option == "1":
        roledict[role_name] = Warrior(role_name, role_sex, role_equipment)

    elif option == "2":
        roledict[role_name] = Thug(role_name, role_sex, role_equipment)

room = Room(110)
for i in roledict.keys():
    room.join_room(roomdict, roledict[i])

room_people =list(roomdict.keys())
print(f"{room.room_num}房间有：")
print(room_people)


i = 1
a = roledict[room_people[0]]
b = roledict[room_people[1]]
while 1:
    print("_"*40)
    print(f"第----<{i}>----回合".center(33))
    i = i + 1
    num1 = random.randint(0, 3)
    print(f"{a.name}释放技能——————》", end="")
    b.defense(b)
    if num1 == 0:
        a.attack(b)
    elif num1 == 1:
        a.skill_one(b)
    elif num1 == 2:
        a.skill_two(b)
    elif num1 == 3:
        a.skill_three(b)

    if a.blood <= 0 or b.blood <= 0:
        winner = a.name if a.blood > 0 else b.name
        print(f"{winner}---Win".center(40, "_"))
        break

    num2 = random.randint(0, 3)
    print(f"{b.name}释放技能——————》", end="")
    a.defense(a)
    if num2 ==0:
        b.attack(a)
    elif num2 == 1:
        b.skill_one(a)
    elif num2 == 2:
        b.skill_two(a)
    elif num2 == 3:
        b.skill_three(a)

    if a.blood <= 0 or b.blood <= 0:
        winner = a.name if a.blood > 0 else b.name
        print(f"{winner}---Win".center(40, "_"))
        break
    print(f"{a.name}:hp--{a.blood}    vs   {b.name}:hp--{b.blood}")
    time.sleep(0.5)
    print("_"*40)
